package com.qire.manhua.activity;

import android.os.Bundle;

import com.qire.antsbinder.dal.exception.DataAccessException;
import com.qire.antscore.annotation.DalExceptionObserve;
import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.inject.Autowired;
import com.qire.common.constant.Navigation;
import com.qire.common.constant.Url;
import com.qire.common.inject.EventControllerInjector;
import com.qire.common.inject.ViewModelInjector;
import com.qire.common.support.base.BaseActivity;
import com.qire.common.utils.ThemeUtil;
import com.qire.common.utils.ToastHelper;
import com.qire.manhua.R;
import com.qire.manhua.controller.ComicCommentListController;
import com.qire.manhua.databinding.ActivityComicCommentListBinding;
import com.qire.manhua.model.entity.ComicBookEntity;
import com.qire.manhua.model.viewModel.impl.ComicCommentListViewModel;

import androidx.annotation.Nullable;

/**
 * 漫画评论列表页
 */
@RouteMapping(path = Navigation.Page.ComicCommentListPage)
public class ComicCommentListActivity extends BaseActivity<ActivityComicCommentListBinding> {

    @Autowired
    ComicBookEntity comicBookEntity;
    @Autowired
    int chapterId;

    @Autowired(injector = EventControllerInjector.class)
    ComicCommentListController controller;

    @Autowired(injector = ViewModelInjector.class)
    ComicCommentListViewModel viewModel;

    @Override
    public int layoutRid() {
        return R.layout.activity_comic_comment_list;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeUtil.changeStatusBarLightOrDark(this, true, true);

        controller.onAddition(viewModel);
        viewModel.onAddition(controller);

        viewModel.loadComicInfo(comicBookEntity, chapterId);
        viewModel.refreshCommentData();
    }

    @DalExceptionObserve(tags = Url.comment_list)
    public void fetchCommentDataExceptionHandle(DataAccessException e){
        viewModel.refreshLayoutFinish(false);
        viewModel.refreshCommentPanelUI();
        ToastHelper.showToast(e.extraMsg);
    }

}
